package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PStoreOrderStatusVo;
import com.ruoyi.system.domain.bo.PStoreOrderStatusBo;
import com.ruoyi.system.service.IPStoreOrderStatusService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 订单操作记录Controller
 *
 * @author ruoyi
 * @date 2022-08-01
 */
@Validated
@Api(value = "订单操作记录控制器", tags = {"订单操作记录管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/storeOrderStatus")
public class PStoreOrderStatusController extends BaseController {

    private final IPStoreOrderStatusService iPStoreOrderStatusService;

    /**
     * 查询订单操作记录列表
     */
    @ApiOperation("查询订单操作记录列表")
    @SaCheckPermission("system:storeOrderStatus:list")
    @GetMapping("/list")
    public TableDataInfo<PStoreOrderStatusVo> list(PStoreOrderStatusBo bo, PageQuery pageQuery) {
        return iPStoreOrderStatusService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出订单操作记录列表
     */
    @ApiOperation("导出订单操作记录列表")
    @SaCheckPermission("system:storeOrderStatus:export")
    @Log(title = "订单操作记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PStoreOrderStatusBo bo, HttpServletResponse response) {
        List<PStoreOrderStatusVo> list = iPStoreOrderStatusService.queryList(bo);
        ExcelUtil.exportExcel(list, "订单操作记录", PStoreOrderStatusVo.class, response);
    }

    /**
     * 获取订单操作记录详细信息
     */
    @ApiOperation("获取订单操作记录详细信息")
    @SaCheckPermission("system:storeOrderStatus:query")
    @GetMapping("/{oid}")
    public R<PStoreOrderStatusVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("oid") Integer oid) {
        return R.ok(iPStoreOrderStatusService.queryById(oid));
    }

    /**
     * 新增订单操作记录
     */
    @ApiOperation("新增订单操作记录")
    @SaCheckPermission("system:storeOrderStatus:add")
    @Log(title = "订单操作记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PStoreOrderStatusBo bo) {
        return toAjax(iPStoreOrderStatusService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改订单操作记录
     */
    @ApiOperation("修改订单操作记录")
    @SaCheckPermission("system:storeOrderStatus:edit")
    @Log(title = "订单操作记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PStoreOrderStatusBo bo) {
        return toAjax(iPStoreOrderStatusService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除订单操作记录
     */
    @ApiOperation("删除订单操作记录")
    @SaCheckPermission("system:storeOrderStatus:remove")
    @Log(title = "订单操作记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{oids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Integer[] oids) {
        return toAjax(iPStoreOrderStatusService.deleteWithValidByIds(Arrays.asList(oids), true) ? 1 : 0);
    }
}
